﻿package com.saint.elasticity 
{
	import com.saint.utils.Logger;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	/**
	 * ...
	 * @author kembera
	 */
	public class FixedAnchorPoint extends Sprite implements IAnchorPoint 
	{
		
		private var bg:Sprite = new Sprite();
		private var _showSpring:Boolean = true;
		private var _strength:Number;
		public var type:String = "FA";
		private var _buttonSize:Number = 20;
		
		
		public function FixedAnchorPoint(xPos:Number = 0, yPos:Number = 0, showspring:Boolean = false, strength:Number = 0.1 ) 
		{
			Logger.info("FixedAnchorPoint.FixedAnchorPoint");
			
			buttonMode = true;
			
			bg.graphics.beginFill(0xff0000, 0.8);
			bg.graphics.drawCircle( 0, 0, _buttonSize);
			bg.graphics.endFill();
			addChild(bg);
			
			x = xPos;
			y = yPos;
			
			_showSpring = showspring;			
			_strength = strength;			
			
			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
			addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
		}
			
		public function label(val:String):void
		{
			var txt:TextField = new TextField();
			txt.text = val;
			addChild(txt);
		}
		
		
		private function onMouseUpHandler(e:MouseEvent):void 
		{		
			try {
				stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
			}
			catch (e:Error)
			{
				Logger.error("fixedAnchorPoint.onMouseUpHandler - no handler to remove from stage");
			}
			stopDrag();
		}
		
		public function enterFrameEvents(e:Event):void 
		{
			
		}
		
		private function onMouseDownHandler(e:MouseEvent):void 
		{
			stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler, false, 0 , true);
			startDrag(true);
		}
		
		public function getShowSpring():Boolean { return _showSpring; }
		
		public function get strength():Number { return _strength; }
		
		public function set strength(value:Number):void 
		{
			_strength = value;
		}
		
		
		
	}

}